package com.base.helper;

import java.io.UnsupportedEncodingException;
import java.nio.charset.StandardCharsets;

/**
 * 拼多多帮助类
 * 
 * @author Administrator
 *
 */
public class PDDHelper {
	/**
	 * 获取商品列表
	 * 
	 * @param apikey
	 * @param Name
	 * @param OrderBy
	 * @param Page
	 * @param Category
	 * @return
	 * @throws UnsupportedEncodingException
	 */
	public static String getShopping(String apikey, String Name, Integer Page, String Category)
			throws UnsupportedEncodingException {
		if (apikey == null) {
			return null;
		}
		if (Page == null) {
			Page = 0;
		}
		Integer pageSize = 20;// 二十个商品一页
		String url = "http://www.haojingke.com/index.php/api/pdd/myapi?type=goodslist&apikey=" + apikey
				+ "&iscoupon=1&page=" + Page + "&pageSize=" + pageSize;
		if (Name != null && !Name.equals("")) {
			url += "&keyword=" + new String(Name.getBytes(StandardCharsets.UTF_8), "GBK");
		}
		if (Category != null && !Category.equals("")) {
			url += "&cname=" + new String(Category.getBytes(StandardCharsets.UTF_8), "GBK");
		}
		System.out.println(url);
		String json = WebHelper.PostData(url, null, "text/html; charset=UTF-8", null);
		System.out.println(json);
		return json;
	}

	/**
	 * 获取商品详情
	 * 
	 * @param apikey
	 * @param skuid
	 * @return
	 */
	public static String getShoppingDetail(String apikey, String skuid) {
		if (apikey == null || apikey.equals("") || skuid == null || skuid.equals("")) {
			return null;
		}
		String url = "http://www.haojingke.com/index.php/api/pdd/myapi?type=goodsdetail&apikey=" + apikey + "&skuid="
				+ skuid;
		String json = WebHelper.PostData(url, null, "text/html; charset=UTF-8", null);
		System.out.println(json);
		return json;
	}

	/**
	 * 获取转链
	 * 
	 * @param apikey
	 * @param skuid
	 * @return
	 */
	public static String getUnionurl(String apikey, String skuid, String positionId) {
		if (apikey == null || apikey.equals("") || skuid == null || skuid.equals("")) {
			return null;
		}
		String url = "http://www.haojingke.com/index.php/api/pdd/myapi?type=unionurl&apikey=" + apikey + "&materialIds="
				+ skuid;
		if (positionId != null && !positionId.equals("")) {
			url += "&positionId=" + positionId;
		}
		String json = WebHelper.PostData(url, null, "text/html; charset=UTF-8", null);
		System.out.println(json);
		return json;
	}

}